/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data_bases.business;

import Entity.Instance;
import data_bases.DAO.DataInstanceDAO;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import login.beans.ConectionBean;

/**
 *
 * @author JuanFelipe
 */
public class DataInstanceBusiness {
    private static String noData = "No Data";
    /**
     * Metodo para obtener la instancia actual en la base de datos
     * @return Los datos de la instancia de la conexion actual
     */
    public Instance getInstance( Connection currentConnection ) throws SQLException{
        Connection conn = currentConnection;
        String sql = "select * from v$instance";
        Instance instance = null;
        try{
            ResultSet rs = new DataInstanceDAO( conn ).executeStatement( sql );
            
            while( rs.next() ){
                ArrayList<String> stringList = new ArrayList<String>();
//                System.out.println("");
                for(int i = 1 ; i <= rs.getMetaData().getColumnCount() ; i++){
//                    System.out.print(" - "+rs.getString(i) );
                    if( rs.getString(i)==null )
                        stringList.add( "(null)" );
                    else
                        stringList.add( rs.getString(i) );  
                }
                
                instance = new Instance(stringList.get(0), stringList.get(1)
                        , stringList.get(2), stringList.get(3), stringList.get(4)
                        , stringList.get(5), stringList.get(6), stringList.get(7)
                        , stringList.get(8), stringList.get(9), stringList.get(10)
                        , stringList.get(11), stringList.get(12), stringList.get(13)
                        , stringList.get(14), stringList.get(15), stringList.get(16)
                        , stringList.get(17), stringList.get(18), stringList.get(19)
                        );
                        
            }
            
            
        }catch ( SQLException se ){
            throw se;
        }catch( Exception e){
            instance = new Instance(noData, noData, noData, noData, noData
                    , noData, noData, noData, noData, noData, noData, noData
                    , noData, noData, noData, noData, noData, noData, noData
                    , noData);
        }
        
        return instance;
    }
    
}
